<template>
  <div class="meetingInfo">
    <el-form
      ref="form"
      v-loading="loading"
      :model="form"
      :inline="true"
    >
      <el-row style="border-top: 1px solid #DFE6EC;">
        <el-col :span="12">
          <el-form-item :label="$t('会议主题')" prop="title" style="border-right: 0;">
            {{ form.mtBusiness.meetingTitle }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('会议类型')" prop="type">
            {{ form.mtBusiness.mtTypeLabel }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('会议地点')" prop="place" style="border-right: 0;">
            {{ form.mtBusiness.meetingAddressName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('会议时间')" prop="time">
            {{ form.mtBusiness.meetingTimeString }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('参会人员')" prop="attendees">
            <UserSelect
              v-model="form.attendees"
              disabled
              style="width: 100%"
              :multiple="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('是否参会')" prop="timeConfirm">
            <el-radio-group v-model="timeConfirm">
              <el-radio
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('意见补充')" prop="contextConfirm">
            <el-input v-model="form.contextConfirm" class="textareaBorder" :autosize="{ minRows: 3, maxRows: 10}" type="textarea" :placeholder="$t('意见补充')" />
          </el-form-item>
        </el-col>
        <div v-for="index in form.mtConfirmDealList" :key="index" class="borderBottom">
          <el-col :span="24">
            <div class="el-form-item" style="display: flex;padding: 10px 15px;">
              <div style="flex: 1;font-weight: 700;font-size: 14px;color: #606266;">{{ index.dealName }}</div>
              <div class="conclusion" style="flex: 1;text-align: right;">
                <span style="font-size:14px;">{{ $t("结论") }}：</span>
                <el-radio-group v-model="index.conclusion">
                  <el-radio
                    v-for="dict in conclusionOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                  >{{ $t(dict.dictLabel) }}
                  </el-radio>
                </el-radio-group>
              </div>
            </div>
          </el-col>
          <el-col :span="24">
            <div class="el-form-item">
              <div class="el-form-item__content" style="border: 0;">
                <div v-if="index.fileBaseList.length > 0" class="attachment">
                  <table>
                    <tr>
                      <th style="width: 150px;">{{ $t('附件类型') }}</th>
                      <th>{{ $t('附件名称') }}</th>
                      <th style="width: 150px;">{{ $t('操作') }}</th>
                    </tr>
                    <tr v-for="fileBase in index.fileBaseList" :key="fileBase">
                      <td>{{ fileBase.directoryName }}</td>
                      <td>
                        <el-link type="primary">
                          <a class="link_a" @click="onlinePreview(fileBase, 'view')">{{ fileBase.name }}</a>
                        </el-link>
                      </td>
                      <td v-if="configDownloadEnabled">
                        <el-button
                          size="small"
                          type="text"
                          @click="download(fileBase.id)"
                        >{{ $t('下载') }}</el-button>
                      </td>
                    </tr>
                  </table>
                </div>
                <el-input v-model="index.remark" class="textareaBorder" :autosize="{ minRows: 3, maxRows: 10}" type="textarea" :placeholder="$t('意见')" />
              </div>
            </div>
          </el-col>

        </div>
      </el-row>
    </el-form>

    <!-- 预览附件 -->
    <OnlinePreview ref="OnlinePreview" :preview-tit="previewTit" />
  </div>
</template>
<script>
import { findAll } from '@/api/oa/type/mtType'
import { listOaMeetingRoom } from '@/api/oa/meeting/oaMeetingRoom'
import { getMtConfirmByMeetingId } from '@/api/oa/business/mtConfirm'
import { saveMtConfirm } from '@/api/oa/business/mtConfirm.js'
import { downLoadFileOpen } from '@/utils/zipdownload'
export default {
  data() {
    return {
      form: {},
      previewTit: '',
      // 遮罩层
      loading: false,
      // 会议类型
      mtTypeOptions: [],
      // 会议室设置
      meetingRoomOptions: [],
      // 会议结论字典
      conclusionOptions: [],
      // 是否通过
      timeConfirm: 'Y',
      typeOptions: [],
      rules: {
      },
      // 全局下载开关
      configDownloadEnabled: true
    }
  },
  created() {
    findAll().then(response => {
      this.mtTypeOptions = response.data
    })
    listOaMeetingRoom(null).then(response => {
      this.meetingRoomOptions = response.rows
    })
    this.getDicts('meeting_conclusion').then(response => {
      this.conclusionOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.typeOptions = response.data
    })
    // 全局下载开关
    this.getConfigKeyToDownload('enable_download').then(response => {
      this.configDownloadEnabled = (response.msg === 'true')
    })
    this.$bus.$emit('async_done')
  },
  methods: {
    init(data) {
      this.loading = true
      getMtConfirmByMeetingId(data.id).then(response => {
          this.form = response.data
          this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.minutesOpen = false
      this.$parent.$parent.reset()
    },
    // 预览附件
    onlinePreview(row, type) {
      type === 'review' ? this.previewType = 'review' : this.previewType = 'view'
      this.$refs.OnlinePreview.onlinePreviewFile(row.id, type)
    },
    // 下载
    download(fileId) {
      downLoadFileOpen(fileId)
    },
    /** 提交按钮 */
    submitForm: function(type) {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.form.timeConfirm = this.timeConfirm
            saveMtConfirm(this.form).then(response => {
              if (response.code === 200) {
                if (type === 'process') {
                  // 设置数据id方式启动流程后取消并再次启动会创建多条记录
                  this.form.id = response.data
                  // 启动流程
                  this.startProcess(response.data)
                } else {
                  this.msgSuccess(this.$t('保存成功'))
                  this.$emit('resetDetailList')
                  try {
                    this.closeForm()
                  } catch (e) {
                    console.log(e)
                  }
                }
                resolve()
              } else {
                reject()
                this.msgError(response.msg)
              }
              this.loading = false
            })
          }
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
